package com.mtung.concurrent.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * @author zhenguo.yao
 * @date 2020/12/16
 */
public class Thread03 implements Callable<String> {
    @Override
    public String call() throws Exception {
        Thread.sleep(5000);
        return "子线程名字" + Thread.currentThread().getName();
    }

    public static void main(String[] args) throws Exception {
        System.out.println("线程名: " + Thread.currentThread().getName());
        long start = System.currentTimeMillis();
        FutureTask<String> stringFutureTask = new FutureTask<>(new Thread03());
        new Thread(stringFutureTask).start();
        System.out.println(stringFutureTask.get());
        System.out.println("耗时: " + (System.currentTimeMillis() - start));
    }

}
